import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import { getToken } from '@/utils/auth'

export const BASE_URL = ' http://localhost:52601'
// create an axios instance
const service = axios.create({
  baseURL: BASE_URL,
  withCredentials: true,
  timeout: 60*1000, 
  'Content-Type': 'application/json'
})

// request interceptor
service.interceptors.request.use(
  config => {
    config.headers['Authorization'] = getToken()
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  response => {
    const res = response.data
    return res
  },
  error => {
    // console.log('err:', error)
    Message({
      message: error,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export default service
